<PageHeader as |p|>
  <p.levelLeft>
    <h1 class="title is-3">
      Authentication Methods
    </h1>
  </p.levelLeft>
</PageHeader>

<Toolbar>
  <ToolbarActions>
    <ToolbarLink @type="add" @params={{array 'vault.cluster.settings.auth.enable'}} data-test-auth-enable>
      Enable new method
    </ToolbarLink>
  </ToolbarActions>
</Toolbar>

{{#each (sort-by "path" model) as |method|}}
  {{#if (contains method.methodType (supported-managed-auth-backends))}}
    <LinkedBlock @params={{array
    "vault.cluster.access.method"
    method.id}} class="list-item-row" data-test-auth-backend-link={{method.id}}>
      <div class="level is-mobile">
        <div class="level-left">
          <div>
            <ToolTip @horizontalPosition="left" as |T|>
              <T.trigger>
                <Icon @glyph={{if
                  (or
                    (find-by "type" method.methodType (mountable-auth-methods))
                    (eq method.methodType "token")
                  )
                  method.methodType
                  "auth"
                }} @size="l" class="has-text-grey-light" />
              </T.trigger>
              <T.content @class="tool-tip">
                <div class="box">
                  {{method.methodType}}
                </div>
              </T.content>
            </ToolTip>
            <span data-test-path data-test-id={{method.id}} class="has-text-weight-semibold has-text-black">
              {{method.path}}
            </span>
            <br />
            <code class="has-text-grey is-size-8">
            {{method.accessor}}
            </code>
          </div>
        </div>
        <div class="level-right is-flex is-paddingless is-marginless">
          <div class="level-item">
            <PopupMenu @name="auth-backend-nav">
              <Confirm as |c|>
              <nav class="menu">
                <ul class="menu-list">
                  <li>
                    <LinkTo @route="vault.cluster.access.method.section" @models={{array method.id "configuration"}}>
                      View configuration
                    </LinkTo>
                  </li>
                  {{#if method.canEdit}}
                    <li>
                      <LinkTo @route="vault.cluster.settings.auth.configure" @model={{method.id}}>
                        Edit configuration
                      </LinkTo>
                    </li>
                  {{/if}}

                  {{#if (and (not-eq method.methodType 'token') method.canDisable)}}
                    <li class="action">
                        <c.Message
                          @id={{method.id}}
                          @title="Disable method?"
                          @message="This may affect access to Vault data."
                          @triggerText="Disable"
                          @onConfirm={{perform disableMethod method}}>
                          </c.Message>
                    </li>
                  {{/if}}
                </ul>
              </nav>
              </Confirm>
            </PopupMenu>
          </div>
        </div>
      </div>
    </LinkedBlock>
  {{else}}
    <div class="list-item-row" data-test-auth-backend-link={{method.id}}>
      <div class="level is-mobile">
        <div class="level-left">
          <div>
            <ToolTip @horizontalPosition="left" as |T|>
              <T.trigger>
                <Icon @glyph={{if
                      (or
                        (find-by "type" method.methodType (mountable-auth-methods))
                        (eq method.methodType "token")
                      )
                      method.methodType
                      "auth"
                    }} @size="l" class="has-text-grey-light" />
              </T.trigger>
              <T.content @class="tool-tip">
                <div class="box">
                  {{method.methodType}}
                </div>
              </T.content>
            </ToolTip>
            <span data-test-path data-test-id={{method.id}} class="has-text-weight-semibold has-text-grey">
              {{method.path}}
            </span>
            <br />
            <code class="has-text-grey is-size-8">
            {{method.accessor}}
            </code>
          </div>
        </div>
        <div class="level-right is-flex is-paddingless is-marginless">
          <div class="level-item">
            <PopupMenu @name="auth-backend-nav">
              <Confirm as |c|>
                <nav class="menu">
                  <ul class="menu-list">
                    <li>
                      <LinkTo @route="vault.cluster.access.method.section" @models={{array method.id "configuration"}}>
                        View configuration
                      </LinkTo>
                    </li>
                    {{#if method.canEdit}}
                      <li>
                        <LinkTo @route="vault.cluster.settings.auth.configure" @model={{method.id}}>
                          Edit configuration
                        </LinkTo>
                      </li>
                    {{/if}}

                    {{#if (and (not-eq method.methodType 'token') method.canDisable)}}
                      <li class="action">
                        <c.Message @id={{method.id}} @title="Disable method?"
                          @message="This may affect access to Vault data." @triggerText="Disable"
                          @onConfirm={{perform disableMethod method}}>
                        </c.Message>
                      </li>
                    {{/if}}
                  </ul>
                </nav>
              </Confirm>
            </PopupMenu>
          </div>
        </div>
      </div>
    </div>
    {{/if}}
{{/each}}
